package control.panel
{
	import events.ModelDataEvent;
	
	import flash.utils.getTimer;
	
	import view.panel.friend.FriendPanel;

	public class FriendPanelControl extends PanelControl
	{
		private var lastOpenTime:int;
		private var queryDelayTimer:int = 10000;
		
		public function FriendPanelControl()
		{
			initPanel();
			initListener();
			
		}
		
		private function initListener():void
		{
			_model.friendModel.addEventListener(ModelDataEvent.UPDATE,onUpdate);
		}
		
		private function onUpdate(event:ModelDataEvent):void
		{
			_view.friendPanel.update(event.datas);
		}
		
		
		private function initPanel():void
		{
			_view.friendPanel = new FriendPanel(this);
			
		}
		
		public function deleteFriend():void
		{
			_model.friendModel.sendDeleteFriend();
		}
		
		public function openOrClose():void
		{
			if (_view.friendPanel.parent)
			{
				return;
			}
			else
			{
				_view.friendPanel.open();
				if (lastOpenTime == 0 || getTimer() - lastOpenTime >= queryDelayTimer)
				{
					_model.netRemote.queryFriendList();
					lastOpenTime = getTimer();
				}
			}
		}
		
	}
}